package com.admin.business.portalWebsite.venusHouseRentTenant;

import com.tiangong.framework.annotation.OpenApi;
import com.tiangong.framework.bo.CDO;
import com.tiangong.framework.bo.Return;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;

/**
 * @description: 租户记录表
 * @create: 2023-11-21 14:18:29
 **/
@Service("venusHouseRentTenantService")
@Slf4j
public class VenusHouseRentTenantService{

    @Resource
    VenusHouseRentTenantDao venusHouseRentTenantDao;

    /**
     * 添加租户记录表,获取id数据
     *
     * @param cdoRequest - id:主键id
     *                   - hrs_id:租售id
     *                   - names:姓名
     *                   - number:电话
     *                   - id_card_positive:身份证正面
     *                   - id_card_side:身份证反面
     *                   - sexs:性别1.男2.女
     *                   - nation:民族
     *                   - birthday:出生日期
     *                   - rent_count:租住人数
     *                   - rent_money:租金
     *                   - payment_method:付款方式
     *                   - deposit_money:押金
     *                   - rent_begin_time:出租开始时间
     *                   - rent_end_time:出租结束时间
     *                   - water_meter:水表数
     *                   - watt_meter:电表数
     *                   - natural_meter:天然气数
     *                   - property_fee:物业费
     *                   - rent_contarct:租赁合同
     *                   - update_time:更新时间
     *                   - begin_time:创建时间
     *                   - state:是否删除：0、正常，1、已删除；
     *                   - card_status:卡状态 ：1.未缴 2.已缴
     * @return
     * @author wdf
     * @create: 2023-11-21 14:18:29
     */
    @OpenApi
    public Return addVenusHouseRentTenant(CDO cdoRequest) {
        venusHouseRentTenantDao.addVenusHouseRentTenant(cdoRequest);
        CDO cdoResult = new CDO();
        if (cdoRequest.containsKey("id")) {
            cdoResult.set("id", cdoRequest.get("id"));
        }
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据id，更新租户记录表数据
     *
     * @param cdoRequest - id:主键id
     *                   - hrs_id:租售id
     *                   - names:姓名
     *                   - number:电话
     *                   - id_card_positive:身份证正面
     *                   - id_card_side:身份证反面
     *                   - sexs:性别1.男2.女
     *                   - nation:民族
     *                   - birthday:出生日期
     *                   - rent_count:租住人数
     *                   - rent_money:租金
     *                   - payment_method:付款方式
     *                   - deposit_money:押金
     *                   - rent_begin_time:出租开始时间
     *                   - rent_end_time:出租结束时间
     *                   - water_meter:水表数
     *                   - watt_meter:电表数
     *                   - natural_meter:天然气数
     *                   - property_fee:物业费
     *                   - rent_contarct:租赁合同
     *                   - update_time:更新时间
     *                   - begin_time:创建时间
     *                   - state:是否删除：0、正常，1、已删除；
     *                   - card_status:卡状态 ：1.未缴 2.已缴
     * @return
     * @author wdf
     * @create: 2023-11-21 14:18:29
     */
    @OpenApi
    public Return updateVenusHouseRentTenantById(CDO cdoRequest) {
        venusHouseRentTenantDao.updateVenusHouseRentTenantById(cdoRequest);
        return Return.SUCCESS;
    }

    /**
     * 根据id，删除租户记录表数据
     *
     * @param cdoRequest - id:主键id
     * @return
     * @author wdf
     * @create: 2023-11-21 14:18:29
     */
    @OpenApi
    public Return deleteVenusHouseRentTenantById(CDO cdoRequest){
        int count = venusHouseRentTenantDao.deleteVenusHouseRentTenantById(cdoRequest.getLong("id"));
        CDO cdoResult = new CDO();
        cdoResult.set("count", count);
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据条件，删除租户记录表数据
     *
     * @param cdoRequest
     * @return
     * @author wdf
     * @create: 2023-11-21 14:18:29
     */
    @OpenApi
    public Return deleteVenusHouseRentTenant(CDO cdoRequest) {
        int count = venusHouseRentTenantDao.deleteVenusHouseRentTenant(cdoRequest);
        CDO cdoResult = new CDO();
        cdoResult.set("count", count);
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据ID，获取租户记录表数据
     *
     * @param cdoRequest - id:主键id
     * @return
     * @author wdf
     * @create: 2023-11-21 14:18:29
     */
    @OpenApi
    public Return getVenusHouseRentTenantById(CDO cdoRequest) {
        CDO cdoMapperResult = venusHouseRentTenantDao.getVenusHouseRentTenantById(cdoRequest.getLong("id"));
        return Return.valueOf(cdoMapperResult);
    }

    /**
     * 根据非空条件，获取租户记录表数据列表
     *
     * @param cdoRequest
     * @return
     * @author wdf
     * @create: 2023-11-21 14:18:29
     */
    @OpenApi
    public Return getVenusHouseRentTenantListPage(CDO cdoRequest) {
        Integer pageIndex = cdoRequest.getInteger("pageIndex")-1;
        int recordSize = 10;
        cdoRequest.set("recordFrom", pageIndex * recordSize);
        cdoRequest.set("recordSize", recordSize);
        List<CDO> cdoMapperResultList = venusHouseRentTenantDao.getVenusHouseRentTenantListPage(cdoRequest);
        boolean isEndPage = false;
        if (cdoMapperResultList.size() < recordSize) {
            isEndPage = true;
        }
        CDO cdoResult = new CDO();
        cdoResult.set("isEndPage", isEndPage);
        cdoResult.set("datalist", cdoMapperResultList);
//        int total = venusHouseRentTenantDao.getVenusHouseRentTenantCount(cdoRequest);
//        cdoResult.set("total", total);
        return Return.valueOf(cdoResult);
    }
    /**
     * 根据混合条件，获取租户记录表数据列表
     *
     * @param cdoRequest - id:主键id
     * @return
     * @author wdf
     * @create: 2023-11-21 14:18:29
     */
    @OpenApi
    public Return getVenusHouseRentTenantListPageByCondition(CDO cdoRequest) {
        Integer pageIndex = cdoRequest.getInteger("pageIndex")-1;
        int recordSize = 10;
        cdoRequest.set("recordFrom", pageIndex * recordSize);
        cdoRequest.set("recordSize", recordSize);
        List<CDO> cdoMapperResultList = venusHouseRentTenantDao.getVenusHouseRentTenantListPageByCondition(cdoRequest);
        boolean isEndPage = false;
        if (cdoMapperResultList.size() < recordSize) {
            isEndPage = true;
        }
        CDO cdoResult = new CDO();
        cdoResult.set("isEndPage", isEndPage);
        cdoResult.set("datalist", cdoMapperResultList);
//        int total = venusHouseRentTenantDao.getVenusHouseRentTenantCount(cdoRequest);
//        cdoResult.set("total", total);
        return Return.valueOf(cdoResult);
    }
}
